const app = getApp();

Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    }
  },

  data: {},

  methods: {
    onMaskTap() {
      this.triggerEvent('close');
    },

    onCancel() {
      this.triggerEvent('close');
    },

    onConfirm() {
      wx.showLoading({
        title: '登录中...'
      });

      app.userLogin().then((userInfo) => {
        wx.hideLoading();
        this.triggerEvent('success', { userInfo });
        wx.showToast({
          title: '登录成功',
          icon: 'success'
        });
      }).catch((err) => {
        wx.hideLoading();
        wx.showToast({
          title: '登录失败',
          icon: 'error'
        });
        console.error('登录失败:', err);
        this.triggerEvent('error', { error: err });
      });
    },

    noop() {}
  }
});
